// server.js
const express = require('express');
const http = require('http');
const socketIo = require('socket.io');
const app = express();
const server = http.createServer(app);
const io = socketIo(server);

io.on('connection', (socket) => {
    console.log('Client connected', socket.id);
    socket.on('message', (data) => {
        console.log('Message:', data);
        socket.broadcast.emit('message', data);
    });
    socket.on('disconnect', () => {
        console.log('Client disconnected', socket.id);
    });
});

server.listen(3000, () => {
    console.log('Server is running on http://localhost:3000');
});